From: Yuan Fu Date: Sun, 30 Mar 2025 04:15:02 +0000 (-0700) Subject: Tighten the criteria for a defun in typescript-ts-mode (bug#77369) X-Git-Tag: archive/raspbian/1%30.2+1-2+rpi1^2~2^2~24^2~158 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success/%22http:/www.example.com/cgi/success?a=commitdiff_plain;h=9869aa1a1003fbd4b3c7d51f9cdd7e77bd68d985;p=emacs.git Tighten the criteria for a defun in typescript-ts-mode (bug#77369) * lisp/progmodes/typescript-ts-mode.el: (typescript-ts-mode--defun-type-regexp): New variable (backported from master). (typescript-ts-mode--defun-predicate): New function. (typescript-ts-base-mode): Use new predicate. --- diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el index 0ffcb144771..871dbc2e3dc 100644 --- a/lisp/progmodes/typescript-ts-mode.el +++ b/lisp/progmodes/typescript-ts-mode.el @@ -452,6 +452,27 @@ See `treesit-thing-settings' for more information.") "Nodes that designate sexps in TypeScript. See `treesit-thing-settings' for more information.") +(defvar typescript-ts-mode--defun-type-regexp + (rx bos (or "internal_module" + "interface_declaration" + "class_declaration" + "method_definition" + "function_declaration" + "lexical_declaration") + eos) + "Settings for `treesit-defun-type-regexp'.") + +(defun typescript-ts-mode--defun-predicate (node) + "Check if NODE is a defun." + (pcase (treesit-node-type node) + ("lexical_declaration" + (treesit-node-match-p + (treesit-node-child-by-field-name + (treesit-node-child node 0 'named) + "value") + "arrow_function")) + (_ t))) + ;;;###autoload (define-derived-mode typescript-ts-base-mode prog-mode "TypeScript" "Generic major mode for editing TypeScript. @@ -470,10 +491,8 @@ This mode is intended to be inherited by concrete major modes." '((?\; . after) (?\{ . after) (?\} . before))) ;; Navigation. (setq-local treesit-defun-type-regexp - (regexp-opt '("class_declaration" - "method_definition" - "function_declaration" - "lexical_declaration"))) + (cons typescript-ts-mode--defun-type-regexp + #'typescript-ts-mode--defun-predicate)) (setq-local treesit-defun-name-function #'js--treesit-defun-name) (setq-local treesit-thing-settings